import 'package:flutter/material.dart';
import 'package:mobile_app.core/core/presentation/theme/styles.dart';

part 'user_progress_block_styles.dart';

part 'user_progress_block_text_theme.dart';

class UserProgressBlockTheme extends InheritedTheme {
  UserProgressBlockTheme({
    required Brightness brightness,
    required super.child,
    super.key,
  })  : _brightness = brightness,
        _data = _buildThemeData(
          brightness: brightness,
        );

  final Brightness _brightness;
  final UserProgressBlockThemeData _data;

  static UserProgressBlockThemeData _buildThemeData({
    required Brightness brightness,
  }) {
    return switch (brightness) {
      Brightness.dark => UserProgressBlockThemeData.dark(),
      Brightness.light => UserProgressBlockThemeData.light(),
    };
  }

  static UserProgressBlockThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<UserProgressBlockTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<UserProgressBlockTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return UserProgressBlockTheme(
      brightness: _brightness,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(UserProgressBlockTheme oldWidget) {
    return _brightness != oldWidget._brightness;
  }
}

class UserProgressBlockThemeData {
  const UserProgressBlockThemeData._internal({
    required this.textTheme,
  });

  factory UserProgressBlockThemeData.light() {
    return UserProgressBlockThemeData._internal(
      textTheme: UserProgressBlockTextTheme.light(),
    );
  }

  factory UserProgressBlockThemeData.dark() {
    return UserProgressBlockThemeData._internal(
      textTheme: UserProgressBlockTextTheme.dark(),
    );
  }

  final UserProgressBlockTextTheme textTheme;
}
